<?php

/**
 * 短信配置
 */
namespace app\voip\func;


use app\voip\model\Sms;
use app\voip\model\SmsData;
use app\voip\model\SmsSig;
use app\voip\model\SmsType;

class SmsFunc
{
    static public function getTypeList()
    {

        return SmsType::all();
    }
    /**
     * @param $data
     * @return bool
     */
    static public function addSmsSig($data)
    {
        $obj= new SmsSig($data);
        return $obj->allowField(true)->save();
    }

    /**
     * @param $id
     * @return bool
     */
    static public function delSmsSig($id)
    {
        return SmsSig::destroy($id);
    }

    /**
     * @param $id
     * @return int
     */
    static public function delSmsData($id)
    {
        return SmsData::destroy($id);
    }
    static public function addTypeList($data)
    {
        return SmsType::create($data);
    }

    static public function getInfoList($where,$rows,$param)
    {

        $obj = new Sms();
        return $obj->alias('s1')->join('sms_sig s3','s1.sig=s3.id')->join('sms_data s4','s1.code=s4.id')->join('sms_type s2','s1.tid=s2.id')->where($where)->field('s1.*,s2.name,s3.name signame,s4.number codenumber')->order('s2.id desc')->order('s1.id desc')->paginate($rows,false,['query'=>$param]);
    }

    /**
     * @param $where
     * @param $rows
     * @param $param
     * @return \think\Paginator
     * @throws \think\exception\DbException
     */
    static public function getSmsDataInfoList($where, $rows, $param)
    {
        $obj = new SmsData();
        return $obj->where($where)->order('id desc')->paginate($rows,false,['query'=>$param]);
    }
    /**
     * 短信内容添加
     * @param $data
     * @return false|int
     */
    static public function  addInfo($data)
    {
        $obj = new Sms($data);
        return $obj->allowField(true)->save();
    }

    /**
     * @param $where
     * @return array|false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static public function getSmsInfoList($where)
    {
        $obj = new Sms();
        return $obj->where($where)->order('id desc')->select();
    }


    /**
     * @param $id
     * @return array|false|\PDOStatement|string|\think\Model
     * @throws \think\exception\DbException
     */
    static public function getInfo($id)
    {
        $obj = new Sms();
        return $obj->alias('s1')->join('sms_sig s2','s1.sig=s2.id')
            ->join('sms_data s3','s1.code=s3.id')->where('s1.id',$id)
            ->field('s2.name sig,s1.intro s1intro,s1.is_data,s1.data s1data,s1.title,s1.id sid,s3.data s3data,s3.number code,s1.is_data,s1.data,s2.id sigid,s3.id dataid')->find();
    }


    /**
     * @param $where
     * @return SmsSig[]|false
     * @throws \think\exception\DbException
     */
    static public function getSmsSigList($where)
    {
        return SmsSig::all($where);
    }

    /**
     * @param $where
     * @return SmsData[]|false
     * @throws \think\exception\DbException
     */
    static public function getSmsDataList($where)
    {
        return SmsData::all($where);
    }


    /**
     * @param $data
     * @return SmsData
     */
    static public function smsDataAdd($data)
    {
        return SmsData::create($data);
    }

    /**
     * @param $data
     * @return SmsData
     */
    static public function updateSmsData($data)
    {
        return SmsData::update($data);
    }

    /**
     * @param $data
     * @return false|int
     */
    static public function updateSms($data)
    {
        $obj = new Sms();
        return $obj->isUpdate()->save($data);
    }
}